home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / sysdeps / m68k / fpu / __math.h < prev    next >
C/C++ Source or Header  |  1993-11-10  |  5KB  |  164 lines

  1. /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #ifdef    __GNUC__
  20.  
  21. #include <sys/cdefs.h>
  22.  
  23. #ifdef    __NO_MATH_INLINES
  24. #define    __m81_u(x)    __CONCAT(__,x)
  25. #else
  26. #define    __m81_u(x)    x
  27. #define    __MATH_INLINES    1
  28. #endif
  29.  
  30. #define    __inline_mathop2(func, op)                          \
  31.   extern __inline __const double                          \
  32.   __m81_u(func)(double __mathop_x)                          \
  33.   {                                          \
  34.     double __result;                                  \
  35.     __asm("f" __STRING(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x));\
  36.     return __result;                                  \
  37.   }
  38. #define    __inline_mathop(op)        __inline_mathop2(op, op)
  39.  
  40. __inline_mathop(acos)
  41. __inline_mathop(asin)
  42. __inline_mathop(atan)
  43. __inline_mathop(cos)
  44. __inline_mathop(sin)
  45. __inline_mathop(tan)
  46. __inline_mathop(cosh)
  47. __inline_mathop(sinh)
  48. __inline_mathop(tanh)
  49. __inline_mathop2(exp, etox)
  50. __inline_mathop2(fabs, abs)
  51. __inline_mathop(log10)
  52. __inline_mathop2(log, logn)
  53. __inline_mathop2(floor, intrz)
  54. __inline_mathop(sqrt)
  55.  
  56. __inline_mathop2(__rint, int)
  57. __inline_mathop2(__expm1, etoxm1)
  58.  
  59. #ifdef    __USE_MISC
  60. __inline_mathop2(rint, int)
  61. __inline_mathop2(expm1, etoxm1)
  62. __inline_mathop2(log1p, lognp1)
  63. __inline_mathop(atanh)
  64. #endif
  65.  
  66. extern __inline __const double
  67. __m81_u(__drem)(double __x, double __y)
  68. {
  69.   double __result;
  70.   __asm("frem%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
  71.   return __result;
  72. }
  73.  
  74. extern __inline __const double
  75. __m81_u(ldexp)(double __x, int __e)
  76. {
  77.   double __result;
  78.   double __double_e = (double) __e;
  79.   __asm("fscale%.x %1, %0" : "=f" (__result) : "f" (__double_e), "0" (__x));
  80.   return __result;
  81. }
  82.  
  83. extern __inline __const double
  84. __m81_u(fmod)(double __x, double __y)
  85. {
  86.   double __result;
  87.   __asm("fmod%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
  88.   return __result;
  89. }
  90.  
  91. extern __inline double
  92. __m81_u(frexp)(double __value, int *__expptr)
  93. {
  94.   double __mantissa, __exponent;
  95.   __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value));
  96.   __asm("fgetman%.x %1, %0" : "=f" (__mantissa) : "f" (__value));
  97.   *__expptr = (int) __exponent;
  98.   return __mantissa;
  99. }
  100.  
  101. extern __inline __const double
  102. __m81_u(pow)(double __x, double __y)
  103. {
  104.   double __result;
  105.   if (__y == 0.0 || __x == 1.0)
  106.     __result = 1.0;
  107.   else if (__y == 1.0)
  108.     __result = __x;
  109.   else if (__y == 2.0)
  110.     __result = __x * __x;
  111.   else if (__x == 10.0)
  112.     __asm("ftentox%.x %1, %0" : "=f" (__result) : "f" (__y));
  113.   else if (__x == 2.0)
  114.     __asm("ftwotox%.x %1, %0" : "=f" (__result) : "f" (__y));
  115.   else
  116.     __result = __m81_u(exp)(__y * __m81_u(log)(__x));
  117.   return __result;
  118. }
  119.  
  120. extern __inline __const double
  121. __m81_u(ceil)(double __x)
  122. {
  123.   double __result;
  124.   unsigned long int __ctrl_reg;
  125.   __asm("fmove%.l fpcr, %0" : "=g" (__ctrl_reg));
  126.   /* Set rounding towards positive infinity.  */
  127.   __asm("fmove%.l %0, fpcr" : /* No outputs.  */ : "g" (__ctrl_reg | 0x30));
  128.   /* Convert X to an integer, using +Inf rounding.  */
  129.   __asm("fint%.x %1, %0" : "=f" (__result) : "f" (__x));
  130.   /* Restore the previous rounding mode.  */
  131.   __asm("fmove%.l %0, fpcr" : /* No outputs.  */ : "g" (__ctrl_reg));
  132.   return __result;
  133. }
  134.  
  135. extern __inline double
  136. __m81_u(modf)(double __value, double *__iptr)
  137. {
  138.   double __modf_int = __m81_u(floor)(__value);
  139.   *__iptr = __modf_int;
  140.   return __value - __modf_int;
  141. }
  142.  
  143. extern __inline __CONSTVALUE int
  144. __m81_u(__isinf)(double __value)
  145. {
  146.   /* There is no branch-condition for infinity,
  147.      so we must extract and examine the condition codes manually.  */
  148.   unsigned long int __fpsr;
  149.   __asm("ftst%.x %1\n"
  150.     "fmove%.l fpsr, %0" : "=g" (__fpsr) : "f" (__value));
  151.   return (__fpsr & (2 << (3 * 8))) ? (__value < 0 ? -1 : 1) : 0;
  152. }
  153.  
  154. extern __inline __CONSTVALUE int
  155. __m81_u(__isnan)(double __value)
  156. {
  157.   char __result;
  158.   __asm("ftst%.x %1\n"
  159.     "fsun %0" : "=g" (__result) : "f" (__value));
  160.   return __result;
  161. }
  162.  
  163. #endif    /* GCC.  */
  164.